package cn.kust.apiuser.service.impl;

import cn.kust.microtourismcommon.pojo.dto.MicroTourismUser;
import cn.kust.microtourismcommon.pojo.dto.ResponseResult;
import cn.kust.microtourismcommon.pojo.dto.TokenResult;
import cn.kust.microtourismcommon.pojo.dto.UserNameAvatar;
import cn.kust.microtourismcommon.pojo.request.VerificationCodeDTO;
import cn.kust.microtourismcommon.remote.ServiceUserCenterClient;
import cn.kust.microtourismcommon.util.JwtUtils;
import cn.kust.apiuser.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author WY
 * @data 2022/7/20 21:04
 **/
@Service
@Slf4j
public class IuserServiceImpl implements IUserService {

    @Autowired
    ServiceUserCenterClient serviceUserCenterClient;

    @Override
    public ResponseResult getUserByAccessToken(String accessToken) {
        log.info("accessToken" + accessToken);
        //解析accessToken 拿到手机号
        TokenResult tokenResult = JwtUtils.checkToken(accessToken);
        String phone = tokenResult.getPhone();
        log.info("手机号" + phone);
        //查询信息并返回
        VerificationCodeDTO verificationCodeDTO = new VerificationCodeDTO();

        ResponseResult<MicroTourismUser> userByPhone = serviceUserCenterClient.getUserByPhone(phone);


        return ResponseResult.success(userByPhone.getData());
    }

    @Override
    public ResponseResult getUserById(String id) {
        long userId = Long.parseLong(id);
        ResponseResult<UserNameAvatar> userNameAvatarById = serviceUserCenterClient.getUserNameAvatarById(userId);

        return ResponseResult.success(userNameAvatarById.getData());
    }
}
